package com.dha.caodangcongnghe;

import com.dha.asynctask.XemThongBaoAsyncTask;
import com.dha.status.NetworkStatus;
import com.dha.variable.ThongBaoVariable;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class ThongBao extends Activity {
	private XemThongBaoAsyncTask asyncTask;
	private NetworkStatus networkStatus;
	private String maGiaoVien = null, ngayDang = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_thong_bao);
		networkStatus = new NetworkStatus(getBaseContext());

		if (networkStatus.isConnected()) {
			// Nhan gia tri tu intent giao vien put qua
			Intent intentNhan = getIntent();
			
			maGiaoVien = intentNhan.getStringExtra("MaGiaoVien");
			ngayDang = intentNhan.getStringExtra("NgayDang");
			
			asyncTask = new XemThongBaoAsyncTask(ThongBao.this, maGiaoVien, ngayDang);
			asyncTask.execute();

		} else {
			Intent intentLoi = new Intent("SuCoVeKetNoiMang");
			startActivity(intentLoi);
		}

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.menu_thong_bao, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.mn_ThongBao_XemThongBaoMoi:
			if (networkStatus.isConnected()) {
				Intent intentThongBao = new Intent(getBaseContext(),
						ThongBao.class);
				startActivity(intentThongBao);
				this.finish();
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		case R.id.mn_ThongBao_XemTheoTenGiaoVien:
			if (networkStatus.isConnected()) {
				Intent intentDanhSachGiaoVien = new Intent("DanhSachGiaoVien");
				startActivity(intentDanhSachGiaoVien);
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		case R.id.mn_ThongBao_XemTheoNgay:
			Intent itentChonNgay = new Intent("ChonNgay");
			startActivity(itentChonNgay);
			break;
		case R.id.mn_ThongBao_XemTheoNgayVaGiaoVien:
			if (networkStatus.isConnected()) {
				Intent intentNgayVaGiaoVien = new  Intent("XemThongBaoTheoNgayVaGiaoVien");
				startActivity(intentNgayVaGiaoVien);
			} else {
				Intent intentLoi = new Intent("SuCoVeKetNoiMang");
				startActivity(intentLoi);
			}
			break;
		default:
			Toast.makeText(getBaseContext(), "Không hỗ trợ", Toast.LENGTH_SHORT)
					.show();
		}
		return super.onOptionsItemSelected(item);
	}

}
